<!--
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-06-27 14:44:29
 * @LastEditors: voanit
 * @LastEditTime: 2022-06-27 15:08:53
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function params (url) {
      let obj = {}
      // let search = location.search.substr(1) // id=1&name=rose&age=18
      let search = url.substr(1) // id=1&name=rose&age=18
      // console.log(search);
      let arr = search.split('&') //[id=1,name=rose,age=18]
      // console.log(arr);
      arr.forEach(item => {  //  id=1   
        let arr2 = item.split('=') //[id,1]  [name，rose]  [age,18]
        obj[arr2[0]] = arr2[1]  //{id:1}
      })
      // console.log(obj);
      return obj
    }
    console.log(params(location.search));
    /* 方法2：new URLSearchParams(location.search).get('age') */
  </script>
</body>
</html>